<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <h2>今天天气很{{weather}}</h2>
    <button @click='changeWeather'>切换天气</button>

  </div>

  <script>
    Vue.config.productionTip = false

    const vm = new Vue({
      el: '#root',
      data: {
        isHot: true,
        numbers: {
          a: 1,
          b: 1
        }
      },
      methods: {
        changeWeather() {
          this.isHot = !this.isHot
        }
      },
      computed: {
        weather() {
          return this.isHot ? '炎热' : '凉爽'
        }
      },
      watch: {
        // 完整写法
        // immediate: true,
        // deep:true, 
        // isHot: {
        //   handler(newValue, oldValue) {
        //     console.log('isHot被修改了', oldValue, '改成了', newValue)
        //   }
        // }
        isHot(newValue, oldValue) {
          console.log('isHot被修改了', oldValue, '改成了', newValue)
        }
      }
    })


    // 简写
    // vm.$watch('isHot', function (newValue, oldValue) {
    //   console.log('isHot被修改了', oldValue, '改成了', newValue)
    // })

  </script>
</body>

</html>